<script setup lang="ts">
import { useBookStore } from '../stores/bookStore';

const store = useBookStore();
</script>

<template>
  <div class="chapter-list">
    <h3>📚 章节列表</h3>
    <div class="chapters-container">
      <div 
        v-for="(_, index) in store.chapters" 
        :key="index"
        @click="store.playChapter(index)"
        :class="{ 'chapter-item': true, 'current': index === store.currentChapter }"
      >
        <span class="chapter-number">第 {{ index + 1 }} 章</span>
        <span v-if="index === store.currentChapter" class="playing-badge">🎵 播放中</span>
      </div>
    </div>
  </div>
</template>

<style scoped>
.chapter-list {
  flex: 1;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 25px;
  padding: 25px;
  box-shadow: 0 8px 32px rgba(255, 245, 157, 0.15);
  border: 1px solid rgba(255, 245, 157, 0.2);
  transition: all 0.3s ease;
}

.chapter-list:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(255, 245, 157, 0.2);
}

h3 {
  color: #8d6e63;
  margin-bottom: 20px;
  font-size: 1.3rem;
  text-align: center;
  font-weight: 600;
}

.chapters-container {
  max-height: 400px;
  overflow-y: auto;
}

.chapter-item {
  padding: 15px 20px;
  margin: 8px 0;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 10px;
  border: 2px solid transparent;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chapter-item:hover {
  background-color: rgba(255, 253, 231, 0.8);
  border-color: #fdd835;
  transform: translateX(5px);
}

.current {
  background-color: rgba(255, 245, 157, 0.1);
  border-color: #fdd835;
  font-weight: bold;
}

.chapter-number {
  color: #333;
  font-size: 1rem;
}

.playing-badge {
  background: linear-gradient(135deg, #fdd835, #fff59d);
  color: #8d6e63;
  padding: 6px 12px;
  border-radius: 15px;
  font-size: 0.8rem;
  animation: pulse 2s infinite;
  box-shadow: 0 2px 8px rgba(253, 216, 53, 0.3);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}
</style>
